// 文件上传类
import { axios } from "@/plugins/axios";

class FileStore {
  constructor() {
    this.filename = "";
    this.size = 0;
    this.mimetype = "";
    this.stor_loc = "";
    this.url = "";
  }

  static async upload(file, parent_dir = null) {
    const url = process.env.VUE_APP_API_URL + "files/upload";
    let data = new FormData();
    if (parent_dir) {
      data.append("parent_dir", parent_dir);
    }
    data.append("file", file, file.name);

    let config = {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    };
    const res = await axios.post(url, data, config)
    return res.data.file_store;
  }
}

export { FileStore }